<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
<head>
<title>项目管理</title>
<jsp:include page="../inc.jsp"></jsp:include>
<script type="text/javascript">
	var dataGrid;
	var editRow = undefined;

	$(function() {
		dataGrid = $('#dataGrid').datagrid({
			url : '${pageContext.request.contextPath}/projectController/dataGrid',
			fit : true,
			//fitColumns : false,
			border : false,
			pagination : true,
			idField : 'id',
			pageSize : 20,
			pageList : [ 20, 30, 40, 50 , 60 , 70 , 80 , 90 , 100 ],
			sortName : 'name',
			sortOrder : 'desc',
			checkOnSelect : true,
			selectOnCheck : true,
			nowrap : false,
			striped : true,
			//rownumbers : true,
			//singleSelect : true,
			frozenColumns : [ [ {
				field : 'id',
				title : '编号',
				width : 150,
				checkbox : true
			}, {
				field : 'name',
				title : '项目名称',
				width : 80,
				sortable : true,
				editor : {
					type : 'validatebox',
					options : {
						required : true
					}
				}
			} ] ],
			columns : [[{
				"title":"具体项目情况",
				"colspan":24
			}],[ {
            	 field : 'productName',
            	 title : '产品',
            	 rowspan : 2,
            	 width : 70,
            	 editor : {
 					type : 'combobox',
 					options : {
 						valueField : 'productName',
 	 					textField : 'productName',
 	 					url: '${pageContext.request.contextPath}/productController/productCombobox',
 	 					editable : false,
 						required : true
 					}
 				}
             },{
            	 field : 'area',
            	 title : '片区',
            	 rowspan : 2,
            	 width : 80,
            	 editor : {
 					type : 'combobox',
 					options : {
 						valueField : 'area',
 	 					textField : 'area',
 	 					url: '${pageContext.request.contextPath}/areaController/areaCombobox',
 	 					editable : false,
 						required : true
 					}
 				}
             },{
            	 field : 'operationType',
            	 title : '操作类型',
            	 rowspan : 2,
            	 width : 100,
            	 editor : {
 					type : 'textarea',
 					options : {
 						required : true
 					}
 				}
             },{
            	// field : 'operationType',
            	 title : '版本信息',
            	 colspan : 2,
            	 width : 50
             },{
				field : 'type',
				title : '组网类型',
				width : 80,
				rowspan : 2,
				editor : {
					type : 'combobox',
					options : {
						valueField : 'type',
 	 					textField : 'type',
 	 					editable : false,
 	 					data : [{type: 'NFV',type: 'NFV'},{type: 'NFV-F8000',type: 'NFV-F8000'},{type: 'ATCA-PT',type: 'ATCA-PT'},{type: 'ATCA-Oracle',type: 'ATCA-Oracle'}],
						required : true
					}
				}
			},{
				field : 'humanResources',
				title : '人力',
				width : 40,
				rowspan : 2,
				editor : {
					type : 'validatebox',
					options : {
						required : false
					}
				}
			},{
           	 title : '项目状态',
           	 colspan : 3,
           	 width : 50
            },{
				field : 'safeguardPM',
				title : '保障PM',
				width : 60,
				rowspan : 2,
				editor : {
					type : 'validatebox',
					options : {
						required : true
					}
				}
			},{
	           	 title : '项目干系人',
	           	 colspan : 7,
	           	 width : 50
            },{
				field : 'progress',
				title : '项目进展',
				width : 80,
				rowspan : 2,
				editor : {
					type : 'combobox',
					options : {
						editable : false,
						valueField : 'progress',
 	 					textField : 'progress',
 	 					data : [{progress: 'OnGoing',progress: 'OnGoing'},{progress: 'Closed',progress: 'Closed'},{progress: 'Pending',progress: 'Pending'}],
						required : false
					}
				}
			},{
				field : 'startDateTime',
				title : '项目启动时间',
				width : 100,
				rowspan : 2,
				editor : {
					type : 'datebox',
					options : {
						editable : false,
						required : false
					}
				}
			},{
				field : 'operationPlan',
				title : '现网操作计划',
				width : 150,
				rowspan : 2,
				editor : {
					type : 'textarea',
					options : {
						required : false
					}
				}
			},{
				field : 'keyAdvances',
				title : '关键进展',
				width : 300,
				rowspan : 2,
				editor : {
					type : 'textarea',
					options : {
						required : false
					}
				}
			},{
				field : 'risk',
				title : '风险',
				width : 300,
				rowspan : 2,
				editor : {
					type : 'textarea',
					options : {
						required : false
					}
				}
			},{
				field : 'modifydatetime',
				title : '项目记录最新修改时间',
				width : 150,
				rowspan : 2
			} ],[{
				field : 'currentVersion',
				title:"当前版本",
				rowspan : 1,
				editor : {
					type : 'validatebox',
					options : {
						required : false
					}
				}
			}, {
				field : 'targetVersion',
				title:"目标版本",
				rowspan : 1,
				editor : {
					type : 'validatebox',
					options : {
						required : true
					}
				}
			}, {
				field : 'process',
				title:"项目进度",
				rowspan : 1,
				editor : {
					type : 'validatebox',
					options : {
						required : true
					}
				}
			}, {
				field : 'quality',
				title:"项目质量",
				rowspan : 1,
				editor : {
					type : 'validatebox',
					options : {
						required : false
					}
				}
			}, {
				field : 'activeHumanResources',
				title:"实际人力",
				rowspan : 1,
				editor : {
					type : 'validatebox',
					options : {
						required : false
					}
				}
			}, {
				field : 'pmo',
				title:"PMO",
				width : 50,
				rowspan : 1,
				editor : {
					type : 'validatebox',
					options : {
						required : false
					}
				}
			}, {
				field : 'seAndSA',
				title:"SE/SA接口",
				rowspan : 1,
				editor : {
					type : 'validatebox',
					options : {
						required : false
					}
				}
			}, {
				field : 'maintainPM',
				title:"维护接口",
				rowspan : 1,
				editor : {
					type : 'validatebox',
					options : {
						required : false
					}
				}
			}, {
				field : 'servicePM',
				title:"服务接口",
				rowspan : 1,
				editor : {
					type : 'validatebox',
					options : {
						required : false
					}
				}
			}, {
				field : 'frontlinePM',
				title:"一线接口",
				rowspan : 1,
				editor : {
					type : 'validatebox',
					options : {
						required : false
					}
				}
			}, {
				field : 'supportPersonnel',
				title:"出差支撑人员",
				rowspan : 1,
				editor : {
					type : 'validatebox',
					options : {
						required : true
					}
				}
			}, {
				field : 'supportTime',
				title:"出差人员时间",
				width : 100,
				rowspan : 1,
				editor : {
					type : 'datebox',
					options : {
						editable : false,
						required : false
					}
				}
			}] ],
			toolbar : [ {
				text : '增加',
				iconCls : 'pencil_add',
				handler : function() {
					if (editRow != undefined) {
						dataGrid.datagrid('endEdit', editRow);
					}
					if (editRow == undefined) {
						dataGrid.datagrid('insertRow', {
							index : 0, // index start with 0
							row : {
								name : ''
							}
						});
						dataGrid.datagrid('beginEdit', 0);
						editRow = 0;
					}
				}
			}, '-', {
				text : '修改',
				iconCls : 'pencil',
				handler : function() {
					var rows = dataGrid.datagrid('getSelections');
					if (rows.length == 1) {
						if (editRow != undefined) {
							dataGrid.datagrid('endEdit', editRow);
						}
						if (editRow == undefined) {
							var index = dataGrid.datagrid('getRowIndex', rows[0]);
							dataGrid.datagrid('beginEdit', index);
							editRow = index;
							dataGrid.datagrid('unselectAll');
						}
					} else {
						$.messager.show({
							title : '提示',
							msg : '请选择一条记录!',
							timeout : 5000,
							showType : 'slide'
						});
					}

				}
			}, '-', {
				text : '删除',
				iconCls : 'pencil_delete',
				handler : function() {
					var rows = dataGrid.datagrid('getSelections');
					if (rows.length > 0) {
						$.messager.confirm('请确认', '您确定要删除当前所有选择的记录吗？', function(b) {
							if (b) {
								var ids = [];
								for(var i=0;i<rows.length;i++){
									ids.push(rows[i].id)
								}
								$.ajax({
									url : '${pageContext.request.contextPath}/projectController/delete',
									data : {
										ids : ids.join(',')
									},
									dataType : 'json',
									success : function(r) {
										if (r && r.success) {
											dataGrid.datagrid('load');
											dataGrid.datagrid('unselectAll');
											$.messager.show({
												msg : r.msg,
												title : '成功'
											});
											dataGrid.datagrid('acceptChanges');
										} else {
											$.messager.alert('失败', r.msg, 'error');
											dataGrid.datagrid('rejectChanges');
										}
									}
								});
							}
						});
					} else {
						$.messager.alert('提示', '请选择要删除的记录!', 'warning');
					}
				}
			}, '-', {
				text : '保存',
				iconCls : 'disk',
				handler : function() {
					dataGrid.datagrid('endEdit', editRow);
				}
			}, '-', {
				text : '取消编辑',
				iconCls : 'cancel',
				handler : function() {
					dataGrid.datagrid('rejectChanges');
					dataGrid.datagrid('unselectAll');
					editRow = undefined;
				}
			}, '-' ],
			onLoadSuccess : function() {
				parent.$.messager.progress('close');
				$('#searchForm table').show();
				//$(this).datagrid('tooltip');
			},
			onAfterEdit : function(rowIndex, rowData, changes) {
				var inserted = dataGrid.datagrid('getChanges', 'inserted');
				var updated = dataGrid.datagrid('getChanges', 'updated');
				var url = '';
				var operationType = '';
				if (inserted.length > 0) {
					url = '${pageContext.request.contextPath}/projectController/add'
					operationType = '添加'
				}else{
					if (updated.length > 0) {
						url = '${pageContext.request.contextPath}/projectController/edit'
						operationType = '修改'
					}else{
						$.messager.alert('注意', '请修改记录', 'error');
						// 当前编辑索引取消
						editRow = undefined;
						return;
					}
				}
				
				$.ajax({
					url : url,
					data : rowData,
					dataType : 'json',
					success : function(r) {
						if (r && r.success) {
							dataGrid.datagrid('acceptChanges');
							$.messager.show({
								msg : r.msg,
								title : operationType+'成功'
							});
							dataGrid.datagrid('load');
						} else {
							dataGrid.datagrid('rejectChanges');
							$.messager.alert(operationType+'失败', r.msg, 'error');
						}
						// 当前编辑索引取消
						editRow = undefined;
						dataGrid.datagrid('unselectAll');
					}
				});

			},
			onDblClickRow : function(rowIndex, rowData) {
				if (editRow != undefined) {
					dataGrid.datagrid('endEdit', editRow);
				}
				if (editRow == undefined) {
					dataGrid.datagrid('beginEdit', rowIndex);
					editRow = rowIndex;
				}

			}

		});
		
		// 增加回车搜索的功能,千万不能调keyup
		$('#searchFormDiv input').keypress(function(event) {
			if (event.keyCode == '13') {
				searchFun();
				return false;
			}
		});

	});
	
	function searchFun() {
		dataGrid.datagrid('load', $.serializeObject($('#searchForm')));
	}
	
	function cleanFun() {
		$('#searchForm input').val('');
		dataGrid.datagrid('load', {});
	}

</script>
</head>
<body>
	<div id="searchFormDiv" class="easyui-layout" data-options="fit : true,border : false">
		<div data-options="region:'north',title:'查询条件',border:false" style="height: 80px; overflow: hidden;">
			<form id="searchForm">
				<table class="table table-hover table-condensed" style="display: none;">
					<tr>
						<th>产品</th>
						<td><input name="productName" placeholder="" class="span2" /></td>
						<th>目标版本</th>
						<td><input name="targetVersion" placeholder="" class="span2" /></td>
						<th>组网类型</th>
						<td><input name="type" placeholder="" class="span2" /></td>
						<th>项目进展</th>
						<td><input name="progress" placeholder="" class="span2" /></td>
						<td></td>
						<td><a href="#"  onclick="searchFun()" class="btn btn-primary span1">搜索一下</a></td>
						<td></td>
						<td><a href="#"  onclick="cleanFun()" class="btn btn-primary span1">清空条件</a></td>
					</tr>
				</table>
			</form>
		</div>
		<div data-options="region:'center',border:false">
			<table id="dataGrid"></table>
		</div>
	</div>
</body>
</html>